<script>
	import {
		connectSocketInit,
		sendMessage
	} from "@/script/websocket.js";
	// function isTabBarPage() {
	//   const pages = getCurrentPages();
	//   if (pages.length) {
	//     const currentPage = pages[pages.length - 1];
	//     const currentPagePath = currentPage.route;
	//     const tabBarPages = pages.filter(page => page.isTabBar);
	//     return tabBarPages.some(tabBarPage => tabBarPage.route === currentPagePath);
	//   }
	//   return false;
	// }
	export default {
		// globalData:{
		// 	isNav:false
		// },
		onLaunch: async function() {

			if (uni.getStorageSync("isLogin")) {

				let LoginInfo = uni.getStorageSync("isLogin");
				connectSocketInit(0, LoginInfo.UserID)
			} else {

			}

			// tabbar中间按钮点击事件
			// uni.onTabBarMidButtonTap(function(e){
			// 	uni.navigateTo({
			// 		url: "/pages/Home/Console/Console",
			// 		animationType: "slide-in-bottom", // 动画类型
			// 		animationDuration: 150, // 窗口动画持续时间，单位为 ms
			// 		fail(err) {
			// 			console.log(err)
			// 		}
			// 	})
			// })
		},
		onShow: async function(ops) {
			if (uni.getStorageSync("isLogin")) {
				// console.log('getStorageSyncTrue', uni.getStorageSync("isLogin"))
				let LoginInfo = uni.getStorageSync("isLogin");

				connectSocketInit(0, LoginInfo.UserID)
				uni.onSocketOpen((res) => {
					// this.isSocketOpen=true
					// console.log('重新打开socket监听！', res);
				})

				const CurrentPages = getCurrentPages();
				console.log('getCurrentPages', CurrentPages.length);

				if (CurrentPages.length < 2) {
					this.$httpost('/OnLaunch/CheckNewMsg', {}).then(res => {
						// console.log('CheckNewMsg', res);					
						if (res.code == 200) {
							// if (res.data.NewMsg.PersonCount > 0) {
							// 	uni.setTabBarBadge({
							// 		index: 3,
							// 		text: String(res.data.NewMsg.PersonCount)
							// 	})
							// }
							if (res.data.NewMsg.PersonCount > 0 || res.data.NewMsg.GroupCount > 0) {
								uni.showTabBarRedDot({
									index: 3
								})
							}
						}
					});

					this.$httpost('/OnLaunch/CheckMyCount', {}).then(res => {
						// console.log('CheckMyCount', res);					
						if (res.code == 200) {
							if (res.data.MyCount > 0) {
								uni.showTabBarRedDot({
									index: 4
								})
							}
						}
					});
				}

				// sendMessage('joinGroup', 0, LoginInfo.UserID, '回到APP')

			} else {
				// console.log('getStorageSyncFalse', uni.getStorageSync("isLogin"))
			}


			// 	let that = this;
			// 	// 分享统计放到此处的目的是因为热启动会不走onload，导致统计不准确。
			// 	if (ops.scene == 1044) {
			// 		// 分享数据统计
			// 		wx.getShareInfo({
			// 			shareTicket: ops.shareTicket,
			// 			success: function(res){
			// 				var encryptedData = res.encryptedData;
			// 				var iv = res.iv;
			// 				if (ops.shareTicket != false) {
			// 					wx.getShareInfo({
			// 						shareTicket: ops.shareTicket,
			// 						success: function (res) {
			// 							var encryptedData = res.encryptedData;
			// 							var iv = res.iv;
			// 							// 发送请求，后台解析出分享信息
			// 							wx.request({
			// 								url: that.globalData.apiDomainZt + 'xcx/login/xcx',
			// 								data: {
			// 									encry: encryptedData,
			// 									iv: iv,
			// 									key: that.globalData.sessionKey,
			// 									tid: ops.query.tid // 推广者的ID
			// 								},
			// 								method: 'POST',
			// 								header: that.globalData.postHeader,
			// 								success: function(res) {
			// 									// 成功后的逻辑处理

			// 								},
			// 								fail: function (res) {
			// 									// console.log('用户打开', res)
			// 								}
			// 						   })
			// 					   }
			// 				   })
			// 				}
			// 			}
			// 		})
			// 	}
		},
		onHide: function() {

			// uni.closeSocket();

			// if (uni.getStorageSync("isLogin")) {
			// 	let LoginInfo = uni.getStorageSync("isLogin");
			// 	this.$httpost('/Login/outLine', {}).then(res => {
			// 		console.log('outLine', res);

			// 		if (res.data == 1) {
			// 			console.log('用户已离线')
			// 		}
			// 	});
			// }
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import './static/css/common.scss';

	@font-face {
		font-family: "iconfont";
		/* Project id 4605721 */
		src:
			url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAPwAAsAAAAACIQAAAOiAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFQGYACDHAqEMINSATYCJAMQCwoABCAF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DBFZbSv9cBz6OPAAexJVFSEEV5oXSOhZG5BdHUEGrVcSWHRPXlYSWRCDgCEZSCOE24jxdQCmGcSPkoH56LxKh3j1xEDSZTSGhrMM5vCj49nnVhHMgGDKGEJTIoJ3yov9cR8ljkbk870DIpfL8FAAAA') format('woff2'),
			url('/static/iconfont/iconfont.woff?t=1719884020239') format('woff'),
			url('/static/iconfont/iconfont.ttf?t=1719884020239') format('truetype');
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.icon-fenxiang1:before {
		content: "\e600";
	}

	.icon-dianzan:before {
		content: "\e8ad";
	}

	.icon-dianzan1:before {
		content: "\e8c3";
	}


	/deep/::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
	}

	::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}


	body {
		background-color: $uni-bg-color-grey;
		font-size: 28rpx;
		color: #505050;
	}

	.flexbc {
		display: flex;
		justify-content: space-between;
	}

	.flexwc {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap
	}

	.commCards {
		clear: both;
		background-color: #FFF;
		padding: 40rpx;
		margin-top: 20rpx;
	}

	.commCardTitle {
		font-size: 32rpx;
		font-weight: bold;
		color: #505050;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.geline {
		padding-left: 20rpx;
		padding-right: 20rpx;
	}

	.box-content {
		/* 跟屏幕高度一样高,不管view中有没有内容,都撑开屏幕高的高度 */
		height: 100vh;
		overflow: auto;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.flex-js {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.box-content::-webkit-scrollbar {
		/* ::-webkit-scrollbar webkit的伪元素，滚动条 
		伪元素只能有一个，不能多个同时出现，且只能放在最后面	
		两个冒号是css3的样式，主要与伪类区分。
	*/
		width: 0;
		height: 0;
		background-color: transparent;
	}
</style>